package com.imooc.distributedjob;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @Description :
 * @Author : YTY
 * @Date : 2021-02-08 12:59
 */

@Slf4j
@Component
public class MyXxlJob {

    @XxlJob("myXxlJobHandler")
    public ReturnT<String> execute(String param) {

        log.info("myXxlJobHandler execute...");
        try {
            Thread.sleep(6666L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        ShardingUtil.ShardingVO shardingVo = ShardingUtil.getShardingVo();

//        List<Integer> list = Arrays.asList(1, 2, 3, 4);
//        for (Integer i : list) {
//            if (i % shardingVo.getTotal() == shardingVo.getIndex()) {
//                log.info("myXxlJobHandler execute...user={}, shardingVo={}",
//                        i, new Gson().toJson(shardingVo));
//            }
//        }

        XxlJobLogger.log("myXxlJobHandler execute...");
        return ReturnT.SUCCESS;
    }
}
